import java.util.HashMap;
import java.util.List;

public class FIFO extends Strategy {

	HashMap<Integer, Integer> memory = new HashMap<Integer, Integer>();
	Queue<Integer> queue = new Queue<Integer>();

	public FIFO(int numFrames, List<Request> requests) {
		super(numFrames, requests);
	}

	public void run() {
		for (Request req : requests) {
			if (memory.containsKey(req.value)) {
				hit++;
			} else {
				if (memory.size() >= frameSize) {
					int removed = queue.getNext().value;
					memory.remove(removed);
				}
				memory.put(req.value, req.value);
				queue.addNode(new Node<Integer>(req.value));
			}
		}
	}

	public void reset() {
		memory = new HashMap<Integer, Integer>();
		queue = new Queue<Integer>();
		hit = 0;
	}

	public static String getName() {
		return "FIFO";
	}
}
